<form class="layui-form seller-form">
    <div class="layui-form-item">

        <div class="layui-inline">
            <button type="button" class="layui-btn layui-btn-sm add-store"><i class="layui-icon">&#xe608;</i> 添加</button>
        </div>

    </div>
</form>

<div class="table-body">
    <table class="layui-table" id="storeTable" lay-filter="storeTable"></table>
</div>

<script>
    layui.use(['table','form'], function(){
        var table = layui.table,form = layui.form;

        table.render({
            elem: '#storeTable',
            height: 'full-330',
            cellMinWidth: '80',
            page: 'true',
            limit:'20',
            id:'storeTable',
            url: "{:url('Store/index')}",
            cols: [[ //标题栏
                {type: 'numbers'},
                {field: 'store_name', width:200, title: '门店名称'},
                {field: 'logo', title: 'LOGO' ,align:'center',width:100, templet: function(data){
                    return '<a href="javascript:void(0);" onclick=viewImage("'+data.logo+'")><image style="max-width:30px;max-height:30px;" src="'+data.logo+'"/></a>';
                }},
                {field: 'mobile', title: '门店电话',align:'center',width:120},
                {field: 'linkman',title: '联系人',align:'center',width:100},
                {field: 'area', title: '门店地区'},
                {field: 'address', title:  '详细地址'},
                {field: 'ctime', sort: true, width:200, title: '创建时间',align:'center'},
                {field: 'utime', sort: true, width:200, title: '更新时间',align:'center'},
                {title:'操作',align:'center',toolbar:'#storeBar',fixed:'right',width: 150}
            ]] //设置表头
        });

        $(document).on('click','.add-store',function(){
           window.location.href = "{:url('Store/add')}";
        });

        //监听工具条
        table.on('tool(storeTable)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

            if(layEvent === 'del'){ //删除
                layer.confirm('真的删除么',{icon:3}, function(index){
                    JsGet("{:url('Store/del')}?id="+data.id,function(res){
                        if(res.status){
                            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                            layer.close(index);//向服务端发送删除指令
                        }
                        layer.msg(res.msg);
                    });
                });
            } else if(layEvent === 'edit'){
                window.location.href = "{:url('Store/edit')}?id="+data.id;
            }
        });
    });
</script>

<script type="text/html" id="storeBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>